package sbt.selenium.pages;

import static org.openqa.selenium.support.ui.ExpectedConditions.presenceOfElementLocated;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;

public class AddNewFilmPage extends AnyPage {
	
	public AddNewFilmPage(PageManager pages) {
		super(pages);
	}
	
	@FindBy(name = "name")
	private WebElement filmTitleField;
	
	@FindBy(name = "year")
	private WebElement filmYearField;
	
	@FindBy(id = "submit")
	private WebElement submitButton;
	
	public AddNewFilmPage setFilmTitleField(String text) {
		filmTitleField.sendKeys(text);
		return this;
	}
	
	public AddNewFilmPage setFilmYearField(String text) {
		filmYearField.sendKeys(text);
		return this;
	}
	
	 public FilmViewPage clickSubmitButton() {
		 submitButton.click();
		 return pages.filmViewPage;
	 }
	 
	 public AddNewFilmPage ensurePageLoaded() {
		    super.ensurePageLoaded();
		    wait.until(presenceOfElementLocated(By.id("submit")));
		    return this;
     }
	 
	 public FilmViewPage ensureFilmAdded() {
		    wait.until(presenceOfElementLocated(By.xpath(".//*[@id='movie']//h2")));
		    return pages.filmViewPage;
  }

	public void ensureErrorsOnPage() {
		//presenceOfElementLocated(By.xpath(""))
		wait.until(presenceOfElementLocated(By.xpath(".//*[@id='updateform']//label[@for='name']")));
		wait.until(presenceOfElementLocated(By.xpath(".//*[@id='updateform']//label[@for='year']")));
		// TODO Auto-generated method stub
		
	}

}
